

var pageContext = new PageContextDatatable(settings||{});
pageContext.setting.canShowFire = true;

pageContext.getOtherOperBtn = function(id,label,record){
	var html = [];	
	if(pageContext.setting.canShowFire){
		html.push('<li>');
		html.push('<a href="javacript:void(0)" label="'+label+'" url="'+window.global.getFinalUrl(window.global.ctx+'/frm/item/val/index?itemId='+record.id)+'"  val="'+id+'" class="tooltip-success propBtn" data-rel="tooltip" title="表单项值信息">');
		html.push('<span class="green">');
		html.push('<i class="ace-icon fa fa-flask bigger-120"></i>');
		html.push('</span>');
		html.push('</a>');
		html.push('</li>');
	}
	return html.join("");
}
pageContext.getOtherPingPuOperBtn = function(id,label,record){
	var html = [];
	if(pageContext.setting.canShowFire){
		html.push('<button class="btn btn-xs btn-info propBtn" url="'+window.global.getFinalUrl(window.global.ctx+'/frm/item/val/index?itemId='+record.id)+'"  label="'+label+'" val="'+id+'" title="表单项值信息">');
		html.push('<i class="ace-icon fa fa-flask bigger-120"></i>');
		html.push('</button>');
	}
	return html.join("");
}
pageContext.renderAfterEventOther = function(){
	$('#'+pageContext.setting.tableId+' >tbody').delegate("tr > td .propBtn","click",function(e){
		 var val = $(this).attr("val");
		 var label = $(this).attr("label");
		 var url = ($(this).attr("url"));
		 var action = window.global.getFinalUrl(url);
		 load(action,"page-content",true,"表单项【"+label+"】值信息",function(){
				
		 });
	     return false;
	});
}
pageContext.toAdd = function(option){
	var action = window.global.getFinalUrl(pageContext.setting.toAddUrl);
	load(action,"page-content",true,"新增"+pageContext.modelName,function(){
		
	});
}
pageContext.toDetail = function(id,data){
	var action = window.global.getFinalUrl(pageContext.setting.toDetailUrl);
	action = window.global.addPara(action,"id",id,true)
	load(action,"page-content",true,pageContext.modelName+"详情",function(){
		
	});
}
pageContext.toUpdate = function(id,data){
	var action = window.global.getFinalUrl(pageContext.setting.toUpdateUrl);
	action = window.global.addPara(action,"id",id,true)
	load(action,"page-content",true,"修改"+pageContext.modelName,function(){
		
	});
}
var searchTreesetting = {
		view: {
			dblClickExpand: false
		},
		data: {
			simpleData: {
				enable: true
			}
		},
		callback: {
			 onClick: onInputTreeClickSearch,
			 beforeClick: zTreeBeforeClick
		}
}; 

var treeSetting = {
		dialog:false
		,onInputTreeBodyDown:onInputTreeBodyDown
		,target:$("#searchForm").find("input[name='tableId']").next("input")
}
var pageContextInputTree = new PageContextInputTree(treeSetting);

function onInputTreeClickSearch(e, treeId, treeNode) {
	if(treeNode.type!="table"){
		return false;
	}
	pageContextInputTree.onClickSearch(e, treeId, treeNode);
}
function zTreeBeforeClick(treeId, treeNode, clickFlag) {
    return (treeNode.type=="table");
};

function onInputTreeBodyDown(event) {
	
	var node = $(event.target).closest("li").attr("treenode");
	if (!($(event.target).attr("treehide") || node=="")) {
		pageContextInputTree.hideMenu();
	}
} 
jQuery(function($) {
	 pageContext.init();

	 $.get(window.global.ctx+"/str/table/tree?noPage=1",{},function(result){
		    var data = result;
			if(data){ 
				var list = data;
				pageContextInputTree.initTree($($("#searchForm").find(".ztree")[0]), list,searchTreesetting);
			}
	 })
	 $(document).find("input").each(function(){
		 $(this).attr("autocomplete","off");
	 });
    var layero = $("#searchForm");
	layero.find('select[novalid!="true"]').each(function(){
		var novalid = $(this).attr("noconvert");
		if(novalid!="true"){
			var $span = layero.find(this).select2({
	            language: "zh-CN"
		            ,matcher:select2Matcher})
	            .next("span")
	            ;
		}
	  });
}); 
